package com.luculent.utils;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

public class FPBTableUtils {
	
	
	public static String pinkunhuxinxiliebiao(JsonArray data,String xian){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("LXDH", map.get("aar012") == null?"":map.get("aar012"));
			jo.addProperty("ZJHM",map.get("aac031")== null?"":map.get("aac031"));
			jo.addProperty("JTRKS",map.get("aac017")== null?"":map.get("aac017"));
			jo.addProperty("PKHSX",map.get("aac006")== null?"":map.get("aac006"));
			jo.addProperty("HBH",map.get("aac001")== null?"":map.get("aac001"));
			jo.addProperty("RBH",map.get("aac025")== null?"":map.get("aac025"));
			jo.addProperty("XIAN",xian);
			jo.addProperty("CUN",map.get("aad001")== null?"":map.get("aad001"));
			jo.addProperty("ND",map.get("aar040")== null?"":map.get("aar040"));  
			jo.addProperty("XM",map.get("aac029")== null?"":map.get("aac029"));
			jo.addProperty("SCSBSJ",map.get("aar041")== null?"":map.get("aar041")); 
			jo.addProperty("TPZT",map.get("aar010")== null?"":map.get("aar010")); 
			ja.add(jo);
		}  
		dataList.clear();
        return SQLUtils.toSql("FPB_PKH", ja); 
	}
	
	
	public static String bangfurendanweichaxun(JsonArray data){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("XH", map.get("ROW_ID") == null?"":map.get("ROW_ID"));
			jo.addProperty("LXDH",map.get("AAR012")== null?"":map.get("AAR012"));
			jo.addProperty("HZXM",map.get("AAP001")== null?"":map.get("AAP001"));
			jo.addProperty("HZZJHM",map.get("AAR025")== null?"":map.get("AAR025"));
			jo.addProperty("TPZT",map.get("AAP051")== null?"":map.get("AAP051"));
			jo.addProperty("SBBZ",map.get("AAP004")== null?"":map.get("AAP004"));
			jo.addProperty("TPHSX",map.get("AAR011")== null?"":map.get("AAR011"));
			jo.addProperty("LXDZ",map.get("AAR013")== null?"":map.get("AAR013"));
			jo.addProperty("YZBM",map.get("AAR014")== null?"":map.get("AAR014")); 
			String email = map.get("AAR015")== null?"":map.get("AAR015");
			if(StringUtils.isNotBlank(email)){
				email = email.replaceAll("'","");
				email = email.replaceAll("\\?","");
				email = email.replaceAll("\n","");
				email = email.replaceAll("\\+","");
				email = email.replaceAll("\\/","");
				email = email.replaceAll("\\\\","");
				email = email.replaceAll(";","");
			} 
			jo.addProperty("DZYX",email);
			jo.addProperty("DWID",map.get("AAP110")+""); 
			ja.add(jo);
		}  
		dataList.clear();
        return SQLUtils.toSql("FPB_BFRDW", ja); 
	}
	
	public static String bangfuzerenrenliebiao(JsonArray data,String dwId){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("XH", map.get("ROW_ID") == null?"":map.get("ROW_ID"));
			jo.addProperty("LXDH",map.get("AAR012")== null?"":map.get("AAR012"));
			jo.addProperty("BFRID",map.get("AAK110")== null?"":map.get("AAK110"));
			jo.addProperty("XM",map.get("AAB002")== null?"":map.get("AAB002")); 
			String zjhm = map.get("AAB004")== null?"":map.get("AAB004");
			if(StringUtils.isNotBlank(zjhm)){
				zjhm = zjhm.replaceAll("'",""); 
			} 
			jo.addProperty("ZJHM",zjhm);
			jo.addProperty("XB",map.get("AAB003")== null?"":map.get("AAB003"));
			jo.addProperty("ZZMM",map.get("AAK033")== null?"":map.get("AAK033"));
			jo.addProperty("XL",map.get("AAK036")== null?"":map.get("AAK036"));
			jo.addProperty("FFJB",map.get("AAF031")== null?"":map.get("AAF031")); 
			jo.addProperty("JSTC",map.get("AAK037")== null?"":map.get("AAK037")); 
			jo.addProperty("DWID",dwId);  
			ja.add(jo);
		}  
		
		String sql = SQLUtils.toSql("FPB_BFZRR", ja);
		dataList.clear(); 
        return sql; 
	}
	
	public static String beibangfurenliebiao(JsonArray data,String bfrId){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("XH", map.get("ROW_ID") == null?"":map.get("ROW_ID"));
			jo.addProperty("LXDH",map.get("AAR012")== null?"":map.get("AAR012"));
			jo.addProperty("TPZT",map.get("AAR010")== null?"":map.get("AAR010"));
			jo.addProperty("XM",map.get("AAC029")== null?"":map.get("AAC029")); 
			jo.addProperty("ZJHM",map.get("AAC031")== null?"":map.get("AAC031"));
			jo.addProperty("RS",map.get("AAC017")== null?"":map.get("AAC017"));
			jo.addProperty("PKHSX",map.get("AAC006")== null?"":map.get("AAC006")); 
			String yhkh = map.get("AAC004")== null?"":map.get("AAC004");
			if(StringUtils.isNotBlank(yhkh)){
				yhkh = yhkh.replaceAll("'",""); 
			} 
			jo.addProperty("YHKH",yhkh); 
			jo.addProperty("BFRID",bfrId);
			jo.addProperty("HBH",map.get("AAC001")== null?"":map.get("AAC001"));
			jo.addProperty("HZGRBH",map.get("AAC025")== null?"":map.get("AAC025"));
			jo.addProperty("KSSJ",map.get("AAR020")== null?"":map.get("AAR020"));
			jo.addProperty("JSSJ",map.get("AAR021")== null?"":map.get("AAR021"));
			ja.add(jo);
		}  
		
		String sql = SQLUtils.toSql("FPB_BFFZRR", ja);
		dataList.clear(); 
        return sql; 
	}
	public static String zcgzdbfdw(JsonArray data,String xian,String xiang,String cun){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("SZXIAN", xian);
			jo.addProperty("SZXIANG",xiang);
			jo.addProperty("SZCUN",cun);
			jo.addProperty("DWMC",map.get("AAP001")== null?"":map.get("AAP001")); 
			jo.addProperty("XZQH",map.get("AREA")== null?"":map.get("AREA"));
			jo.addProperty("LSGX",map.get("AAP004")== null?"":map.get("AAP004"));
			jo.addProperty("BFDWLX",map.get("AAP051")== null?"":map.get("AAP051"));  
			jo.addProperty("LXDH",map.get("AAP005")== null?"":map.get("AAP005"));
			jo.addProperty("LXRXM",map.get("AAR011")== null?"":map.get("AAR011"));
			jo.addProperty("LXRDH",map.get("AAR012")== null?"":map.get("AAR012"));
			jo.addProperty("LXDZ",map.get("AAR013")== null?"":map.get("AAR013"));
			jo.addProperty("YZBM",map.get("AAR014")== null?"":map.get("AAR014")); 
			String email = map.get("AAR015")== null?"":map.get("AAR015");
			if(StringUtils.isNotBlank(email)){
				email = email.replaceAll("'","");
				email = email.replaceAll("\\?","");
				email = email.replaceAll("\n","");
				email = email.replaceAll("\\+","");
				email = email.replaceAll("\\/","");
				email = email.replaceAll("\\\\","");
				email = email.replaceAll(";","");
			}  
			jo.addProperty("DZYX",email);
			jo.addProperty("DWID",cun);
			ja.add(jo);
		}   
		String sql = SQLUtils.toSql("FPB_ZCGZDBFDW", ja);
		dataList.clear(); 
        return sql; 
	}
	
	public static String zcgzzcdy(JsonArray data,String dwid){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject();  
			jo.addProperty("BFDWMC",map.get("AAP001")== null?"":map.get("AAP001")); 
			jo.addProperty("XM",map.get("AAB002")== null?"":map.get("AAB002"));
			jo.addProperty("SFDYSJ",map.get("AAK032")== null?"":map.get("AAK032"));
			jo.addProperty("SFDYDZ",map.get("AAK031")== null?"":map.get("AAK031"));  
			jo.addProperty("KSSJ",map.get("AAR020")== null?"":map.get("AAR020"));
			jo.addProperty("JSSJ",map.get("AAR021")== null?"":map.get("AAR021"));
			jo.addProperty("JSTC",map.get("AAK037")== null?"":map.get("AAK037"));
			jo.addProperty("ZWJB",map.get("AAF031")== null?"":map.get("AAF031"));
			jo.addProperty("XB",map.get("AAB003")== null?"":map.get("AAB003"));
			jo.addProperty("ZZMM",map.get("AAK033")== null?"":map.get("AAK033"));
			jo.addProperty("XL",map.get("AAK036")== null?"":map.get("AAK036"));
			jo.addProperty("ZJHM",map.get("AAB004")== null?"":map.get("AAB004"));
			jo.addProperty("LXDH",map.get("AAR012")== null?"":map.get("AAR012"));
			jo.addProperty("LXDZ",map.get("AAR013")== null?"":map.get("AAR013")); 
			jo.addProperty("DWID",dwid);
			ja.add(jo);
		}   
		String sql = SQLUtils.toSql("FPB_ZCGZDZCDY", ja);
		dataList.clear(); 
        return sql; 
	}
	
	public static String xiangmuxinxichaxun(JsonArray data,String xian,String nd){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("XMMC", map.get("acr002") == null?"":map.get("acr002"));
			jo.addProperty("XMLB",map.get("acr005")== null?"":map.get("acr005"));
			jo.addProperty("XMZLB",map.get("acr009")== null?"":map.get("acr009"));
			jo.addProperty("XMYSZTZ",map.get("acr006")== null?"":map.get("acr006")); 
			jo.addProperty("XMZT",map.get("acr221")== null?"":map.get("acr221"));
			jo.addProperty("SYKNHS",map.get("acr333")== null?"":map.get("acr333"));
			jo.addProperty("KSRQ",map.get("aar020")== null?"":map.get("aar020"));
			jo.addProperty("JSRQ",map.get("aar021")== null?"":map.get("aar021")); 
			jo.addProperty("XMBH",map.get("acr010")== null?"":map.get("acr010")); 
			jo.addProperty("SZXIAN",xian);  
			jo.addProperty("ND",nd); 
			ja.add(jo);
		}   
		String sql = SQLUtils.toSql("FPB_XM", ja);
		dataList.clear(); 
        return sql; 
	}
	
	public static String shouyirenliebiao(JsonArray data,String xmbh,String nd){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("XM", map.get("AAC029") == null?"":map.get("AAC029"));
			//jo.addProperty("XB",map.get("acr005")== null?"":map.get("acr005"));
			jo.addProperty("ZJHM",map.get("AAC031")== null?"":map.get("AAC031"));
			//jo.addProperty("PKHSX",map.get("acr006")== null?"":map.get("acr006")); 
			//jo.addProperty("SBBZ",map.get("acr221")== null?"":map.get("acr221"));
			//jo.addProperty("LXDH",map.get("acr333")== null?"":map.get("acr333"));
			jo.addProperty("ZYZPYY",map.get("AAC007")== null?"":map.get("AAC007"));
			jo.addProperty("TPZT",map.get("AAR010")== null?"":map.get("AAR010")); 
			jo.addProperty("XH",map.get("ROW_ID")== null?"":map.get("ROW_ID")); 
			jo.addProperty("XMBH",map.get("ACR010")== null?"":map.get("ACR010"));  
			jo.addProperty("ND",nd); 
			ja.add(jo);
		}   
		String sql = SQLUtils.toSql("FPB_XMSYR", ja);
		dataList.clear(); 
        return sql; 
	}
	
	public static String xiangmuxiangqing(JsonArray data,String xmbh,String nd){
		Gson gson = new Gson();
        List<Map<String,String>> dataList = gson.fromJson(data, new TypeToken<List<Map<String,String>>>() {}.getType());  
        JsonArray ja=new JsonArray(); 
		for(Map<String,String> map : dataList){
			JsonObject jo=new JsonObject(); 
			jo.addProperty("XMMC", map.get("ACR002") == null?"":map.get("ACR002"));
			jo.addProperty("XMZLX",map.get("ACR009")== null?"":map.get("ACR009"));
			jo.addProperty("KSSJ",map.get("AAR020")== null?"":map.get("AAR020"));
			jo.addProperty("JSSJ",map.get("AAR021")== null?"":map.get("AAR021")); 
			jo.addProperty("XMZY",map.get("ACR004")== null?"":map.get("ACR004"));
			jo.addProperty("XMYSZJE",map.get("ACR006")== null?"":map.get("ACR006"));
			//由于不同类型的项目显示的信息不同
//			jo.addProperty("ZYCZZXZJ",map.get("")== null?"":map.get(""));
//			jo.addProperty("SHENGJZXZJ",map.get("AAR010")== null?"":map.get("AAR010")); 
//			jo.addProperty("SHIJZXZJ",map.get("ROW_ID")== null?"":map.get("ROW_ID")); 
//			jo.addProperty("XIANJZXZJ",map.get("ROW_ID")== null?"":map.get("ROW_ID"));
//			jo.addProperty("SHZCZJ",map.get("ROW_ID")== null?"":map.get("ROW_ID"));
//			jo.addProperty("HYBMJE",map.get("ROW_ID")== null?"":map.get("ROW_ID"));
//			jo.addProperty("XDZJ",map.get("ROW_ID")== null?"":map.get("ROW_ID"));
//			jo.addProperty("ZHZJ",map.get("ROW_ID")== null?"":map.get("ROW_ID")); 
			jo.addProperty("XMBH",map.get("ACR010")== null?"":map.get("ACR010"));  
			jo.addProperty("ND",nd); 
			ja.add(jo);
		}   
		String sql = SQLUtils.toSql("FPB_XMXQ", ja);
		dataList.clear(); 
        return sql; 
	}
	
}
